<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\AttributeKey
 *
 * @property int $id
 * @property int $attribute_group_id
 * @property string $key name of attribute
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\AttributeGroup $attributeGroup
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AttributeValue[] $attributeValues
 * @property-read int|null $attribute_values_count
 * @method static \Database\Factories\AttributeKeyFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey query()
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey whereAttributeGroupId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey whereKey($value)
 * @method static \Illuminate\Database\Eloquent\Builder|AttributeKey whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class AttributeKey extends Model
{
    use HasFactory;
	
	protected $guarded = ['id'];
	
	protected $with = ['attributeValues'];
	
	public function attributeGroup()
	{
		return $this->belongsTo(AttributeGroup::class);
	}
	
	public function attributeValues()
	{
		$queries = explode('/', url()->current());
		$id = (int)array_pop($queries);
		return $this->hasMany(AttributeValue::class)->where('product_id', $id);
	}
}
